#include "global.h"
#define LOG_TAG TAG_MISC
#include "misc_log.h"
#include "FreeRTOS.h"
#include "timers.h"
#include "misc_sound.h"
#include "comm/co_heartbeat.h"


/**
 * @brief 播报指定id的音频，超时后调用回调返回结果
 * @param  id               My Param doc
 * @param  timeout_ms       My Param doc
 * @param  cb               My Param doc
 * @return int32_t 
 */
int32_t tbox_sound_play_with_timeout(sound_id_e id, uint32_t timeout_ms, play_timeout_cb_t cb)
{
    /**
     * @todo 待结合仪表实现功能，注意存在低功耗模式下寻车响铃,需要处理对应的低功耗唤醒逻辑
     */
    static TimerHandle_t myTimer = NULL;

    if (NULL == (myTimer = xTimerCreate("sound_play_timer",           // Just a text name, not used by the kernel.
                                        timeout_ms,                   // The timer period in ticks.
                                        pdFALSE,                      // The timers will auto-reload themselves when they expire.
                                        (void *)id,                   // Assign each timer a unique id equal to its array index.
                                        cb)))     // Each timer calls the same callback when it expires.
    {
        log_e("create a poweroff timer failed!\r\n");
        Error_Handler();

        return -EIO;
    }

    if( pdPASS != xTimerStart(myTimer, timeout_ms)) {
		log_e("Start a poweroff timer failed!\r\n");
    }
	
    return SUCC;   
}